package com.SuanZhengYi.YiChang;

public class ExceptionTest1 {
    public static void main(String[] args) {
        try {
            saveAge(16);
            System.out.println("底层执行成功！");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("底层出现了bug！");
        }
        try {
            saveAge2(160);
            System.out.println("底层执行成功！");
        } catch (AgeIllegalException e) {
            e.printStackTrace();
            System.out.println("底层出现了bug！");
        }
    }
    public static void saveAge(int age){
        if(age>0&&age<150){
            System.out.println("年龄保存成功："+age);
        }else {
           throw new AgeIllegalRuntimeException("/age is illegal,your age is"+age);
        }
    }
    public static void saveAge2(int age)throws AgeIllegalException{
        if(age>0&&age<150){
            System.out.println("年龄保存成功："+age);
        }else {
            throw new AgeIllegalException("/age is illegal,your age is"+age);
        }
    }
}
